#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N=110;
const int maxn=1e6;
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

 
void solve()
{
    int n;
    sd(n);
 
    char a[N][N];
    for(int i = 1; i <= n; i ++ )
        scanf("%s", a[i] + 1);
 
    int res = 0;
    for(int i = 1; i <= n; i ++ )
    {
        for(int j = 1; j <= n; j ++ )
            if(a[i][j] != '3')
            {
                int cnt = 0;
                cnt += a[i][j] + a[j][n - i + 1] + a[n - i + 1][n - j + 1] + a[n - j + 1][i] - 4 * '0';
                res += min(cnt, 4 - cnt);
                a[i][j] = a[j][n - i + 1] = a[n - i + 1][n - j + 1] = a[n - j + 1][i] = '3';
            }
    }
 
    cout << res << endl;
 
    return;
}
 
int main()
{
    int T;
    sd(T);
    while(T -- )
        solve();
 
    return 0;
}

